﻿Class Everything
{
    __New(DllPath){
        this.hModule := DllCall("LoadLibrary", "Str", this.DllPath:=DllPath)
    }
    __Get(aName){
    }
    __Set(aName, aValue){
    }
    __Delete(){
        DllCall("FreeLibrary", "UInt", this.hModule) 
        Return
    }
    SetSearch(aValue)
    {
        this.eSearch := aValue
        DllCall(this.DllPath "\Everything_SetSearch","Str",aValue)
        Return
    }
    ;设置全字匹配
    SetMatchWholeWord(aValue)
    {
        this.eMatchWholeWord := aValue
        DllCall(this.DllPath "\Everything_SetMatchWholeWord","Int",aValue)
        Return
    }
    ;执行搜索动作
    Query(aValue=1)
    {
        DllCall(this.DllPath "\Everything_Query","Int",aValue)
        Return
    }
    ;返回匹配总数
    GetTotResults()
    {
        Return DllCall(this.DllPath "\Everything_GetTotResults")
    }
    ;返回文件名
    GetResultFileName(aValue)
    {
        Return strget(DllCall(this.DllPath "\Everything_GetResultFileName","Int",aValue))
    }
    ;返回文件全路径
    GetResultFullPathName(aValue,cValue=128)
    {
        VarSetCapacity(bValue,cValue*2)
        DllCall(this.DllPath "\Everything_GetResultFullPathName","Int",aValue,"Str",bValue,"Int",cValue)
        Return bValue
    }
}
exeQuery(exeName,DllPath){
    static ev:=0
    global Sourceurl
    If !FileExist(DllPath){
        URLDownloadToFile(Sourceurl "/Lib/Dll_x" (A_PtrSize=4?"86":"64") "/Everything.dll", DllPath)
    }
    If (!ev)
        ev := new everything(DllPath)
	str := exeName . " !C:\*Windows* !?:\*cache* !?:\*log* !?:\$RECYCLE.BIN*"
	;查询字串设为全字匹配
	ev.SetMatchWholeWord(true)
	ev.SetSearch(str)
	;执行搜索
	ev.Query()
	Return ev.GetResultFullPathName(0)
}